#pragma once

#include<string.h>
#include<assert.h>
#include<iostream>
using namespace std;

namespace word
{
	class string
	{
	public:
		typedef char* iterator;
		typedef const char* const_iterator;
		iterator begin()
		{
			return _str;
		}
		iterator end()
		{
			return _str + _size;
		}

		const_iterator begin() const
		{
			return _str;
		}
		const_iterator end() const
		{
			return _str + _size;
		}

		string(const char* s = "")
		{
			size_t len = strlen(s);
			_str = new char[len + 1];
			_size = _capacity = len;
			strcpy(_str, s);
		}

		string(const string& s)
		{
			_size = s._size;
			_capacity = s._capacity;
			_str = new char[_capacity + 1];
			strcpy(_str,s._str);
		}

		~string()
		{
			delete[]_str;
			_size = _capacity = 0;
		}

		char* c_str();

		string& operator = (const string& s)
		{
			_size = s._size;
			_capacity = s._capacity;
			_str = new char[_capacity + 1];
			strcpy(_str, s._str);
			return (*this);
		}

		string& reserve(size_t n);
		size_t find(const char* s, size_t pos = 0) const;
		size_t find(const char ch, size_t pos = 0) const;
		string substr(size_t pos, size_t len);
	private:
		char* _str;
		size_t _size;
		size_t _capacity;
		
		static const size_t npos = -1;
	};

	//ostream& operator << (ostream& out, const string& s);
	//std::istream& operator >> (std::istream& in, string& s);
	void test_string();
	void test_string01();
}
